//
//  CustomTabBarController.m
//  dielianw
//
//  Created by 刘威 on 16/9/6.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "CustomTabBarController.h"
#import "CustomNavController.h"
#import "LFYHomeViewController.h"
#import "SYWebViewController.h"
#import "LFCenterViewController.h"
#import "LFMeViewController.h"

@implementation CustomTabBarController 

+ (void)initialize {
    //设置底部样式
    UITabBarItem * appeatance = [UITabBarItem appearance];
    NSMutableDictionary * attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont tabBarTitleFont];
    attrs[NSForegroundColorAttributeName]= [UIColor grayTitleColor];
    NSMutableDictionary * selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSForegroundColorAttributeName]= [UIColor grayTitleColor];
    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];
    [appeatance setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [appeatance setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    [UITabBar appearance].translucent = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;

    CustomNavController *newbieNavController = [[CustomNavController alloc] initWithRootViewController:[self setRootViewController:[LFYHomeViewController new] title:@"首页" image:[UIImage imageNamed:@"tabbar_shopping_icon"] selectedImage:[UIImage imageNamed:@"tabbar_shopping_icon_s"]]];
    
//    SYWebViewController *vc1 = [SYWebViewController new];
//    vc1.requestUrl = [NSURL URLWithString:@"https://cloud.haodai.com/?ref=hd_11017762"];
//    vc1.isTopHidden = YES;
//    
//    SYWebViewController *vc2 = [SYWebViewController new];
//    vc2.requestUrl = [NSURL URLWithString:@"https://baoxian.haodai.com/?media=yun&ref=hd_11017762#/"];
//    vc2.isTopHidden = YES;
//
//
//    SYWebViewController *vc3 = [SYWebViewController new];
//    vc3.requestUrl = [NSURL URLWithString:@"https://shebao.haodai.com/#/?refer=yun&channel=hd_11017762"];
//    vc3.isTopHidden = YES;



    
    CustomNavController *messageNavController = [[CustomNavController alloc] initWithRootViewController:[self setRootViewController:[LFCenterViewController new] title:@"借款" image:[UIImage imageNamed:@"tabbar_center_icon"] selectedImage:[UIImage imageNamed:@"tabbar_center_icon_s"]]];
    
    CustomNavController *messageNavController2 = [[CustomNavController alloc] initWithRootViewController:[self setRootViewController:[LFMeViewController new] title:@"我的" image:[UIImage imageNamed:@"tabbar_me_icon"] selectedImage:[UIImage imageNamed:@"tabbar_me_icon_s"]]];
    
//    CustomNavController *messageNavController3 = [[CustomNavController alloc] initWithRootViewController:[self setRootViewController:vc3 title:@"社保" image:[UIImage imageNamed:@"tabbar_me_icon"] selectedImage:[UIImage imageNamed:@"tabbar_me_icon_s"]]];
    
    self.viewControllers = @[newbieNavController,messageNavController,messageNavController2];
}

- (UIViewController *)setRootViewController:(UIViewController *)viewController
                        title:(NSString *)title
                        image:(UIImage *)image
                  selectedImage:(UIImage *)selectedImage {
    viewController.navigationItem.title= title;
    viewController.tabBarItem.title = title;
    viewController.tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    viewController.tabBarItem.selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    viewController.view.backgroundColor = [UIColor whiteColor];
    return viewController;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];
    NSLog(@"%ld",(long)index);
}

@end
